# -*- coding: utf-8 -*-
import time
from odoo import api, fields, models, _
import odoo.addons.decimal_precision as dp
from odoo.exceptions import UserError
import calendar
class fhtest_tbclue(models.TransientModel):
    _name = 'fhtest.tbclue'
    _description = u'线索'

    fsex=fields.Selection([('0',u'是'),('1',u'否')],u'性别',readonly=False,required=False,translate=False)
    fsource=fields.Many2one('hr.employee',u'线索来源',readonly=False,required=False,translate=False)
    fmobile1= fields.Char(u'手机1',readonly=False,required=False,translate=False)
    fmobile2= fields.Char(u'手机2',readonly=False,required=False,translate=False)
    fweixin= fields.Char(u'微信号',readonly=False,required=False,translate=False)
    fqq= fields.Char(u'QQ',readonly=False,required=False,translate=False)
    femail= fields.Char(u'邮箱',readonly=False,required=False,translate=False)
    fregion=fields.Many2one('hr.employee',u'地区',readonly=False,required=False,translate=False)
    faddress= fields.Char(u'地址',readonly=False,required=False,translate=False)
    fstate=fields.Selection([('0',u'是'),('1',u'否')],u'状态',readonly=False,required=False,translate=False)
    ffollowuptime=fields.Datetime(u'下次跟进时间',readonly=False,required=False,translate=False)
    fremarks=fields.Text(u'备注',readonly=False,required=False,translate=False)
    fsubordinate=fields.Many2one('hr.employee',u'所属部门',readonly=False,required=False,translate=False)


    fcampus=fields.Many2one('hr.employee',u'校区',readonly=False,required=False,translate=False)
    fcourse=fields.Many2one('hr.employee',u'课程',readonly=False,required=False,translate=False)			
	
	
    def action_cancel(self):
        """
        Closes Phonecall to Phonecall form
        """
        return {'type':'ir.actions.act_window_close'}	
    def FClassbb_id_change(self,fnian,fyuefen,context=None):
        vals={}
        #raise osv.except_osv(_('提示2!'), _(FSchedule))
        tinfo_FSchedule=""
        day_begin=None		
        day_end=None		
        if (fyuefen !=False and fnian !=False) :
		
            #prod_line_ids002=self.pool.get('jfcrm.tbschedule').search(cr, uid, [('id','=',FSchedule)], context=context)
            #tinfo_FSchedule=self.pool.get('jfcrm.tbschedule').browse(cr, uid,prod_line_ids002,context=context)[0].FSchedule
            #day_now = '20151022'
            day_now = fnian+fyuefen+'01'			
            #day_begin = day_now[0:4]+'-'+day_now[4:6]+'-'+'01' #月初肯定是1号 所以 直接替换 就可以
            day_begin = day_now[0:4]+'-'+day_now[4:6]+'-'+'01' #月初肯定是1号 所以 直接替换 就可以			
            monthRange = calendar.monthrange(int(day_now[0:3]),int(day_now[4:6]))#得到本月的天数
            day_end = day_now[0:4]+'-'+day_now[4:6]+'-'+str(monthRange[1])			
        vals={'FRegistrationdate1':day_begin	,'FRegistrationdate2':day_end	}
        return {'value': vals}		     
    def ziyuanxd_fdcrm_create(self):
        model_data = self.env['ir.model.data']
        model_self=super(fhtest_tbclue, self).read(['FSubject','fkemu','fxsname','FGrade','fhheteacher','FRegistrationdate','FRegistrationdate1','FRegistrationdate2','Fsetperiod'])[0]
			
		
        domaincontext=[]
		
        #domaincontext.append(('name_related', 'like', '%'+ model_self_resource_id +'%'))
		
        if(model_self['FSubject']!=False):
			domaincontext.append(('fkemu', 'like', '%'+ model_self['FSubject'][1] +'%'))
			
        if(model_self['fkemu']!=False):
			domaincontext.append(('fkemu', '=', model_self['fkemu']))
        if(model_self['fxsname']!=False):
			domaincontext.append(('fxsname', '=', model_self['fxsname']))
			
        if(model_self['FGrade']!=False):
			domaincontext.append(('fbanji', '=', model_self['FGrade'][1]))
        if(model_self['fhheteacher']!=False):
			domaincontext.append(('fsklaoshi', '=', model_self['fhheteacher'][1]))			
        if(model_self['FRegistrationdate']!=False):
			domaincontext.append(('fdata', '=', model_self['FRegistrationdate']))
			
        if(model_self['FRegistrationdate1']!=False):
			domaincontext.append(('fdata', '>=', model_self['FRegistrationdate1']))
        if(model_self['FRegistrationdate2']!=False):
			domaincontext.append(('fdata', '<=', model_self['FRegistrationdate2']))			
			
        if(model_self['Fsetperiod']!=False):
			domaincontext.append(('fshiduan', '=', model_self['Fsetperiod'][1]))		
        print('---kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk--')
        print(domaincontext)		
        #scontext={"search_default_FAdddateks":model_self.FAdddateks,"search_default_FAdddatejs":model_self.FAdddatejs,}		
			
        value = {
            'view_type': 'form',
            'view_mode': 'tree,form',
            'res_model': 'fhtest.weishui001',
            'res_id': 1,
            'views': [(False, 'tree'),(False, 'form')],
            'type': 'ir.actions.act_window',
            #'domain':domaincontext ,					
        }		
		
        return value		
			
fhtest_tbclue()
